package com.oocl.heather.Service.impl;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import com.oocl.heather.Service.IParser;
import com.oocl.heather.comparator.ICustomerComparator;
import com.oocl.heather.entity.Customer;

public class Parser implements IParser {
//分析器
	public Set<Customer> parse(List<String> list, ICustomerComparator co) {
		// TODO Auto-generated method stub
		Set<Customer> p=new TreeSet<Customer>(co);
		DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
		for (int i = 0; i < list.size(); i++) {
			String item=list.get(i);
			
			String id=item.substring(item.indexOf("id")+2, item.indexOf("name"));
			String name=item.substring(item.indexOf("name")+4,item.indexOf("birth"));
			String birth=item.substring(item.indexOf("birth")+5, item.indexOf("sex"));
			String sex=item.substring(item.indexOf("sex")+3, item.indexOf("email"));
			String email=item.substring(item.indexOf("email")+5);
			
			Customer cs=new Customer();
			try {
				
				cs.setId(Integer.valueOf(id));
				cs.setName(name);
				Date date;
				date = format.parse(birth);
				cs.setBirth(date);
				cs.setSex(sex);
				cs.setEmail(email);
				p.add(cs);
				
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
		
		return p;
	}

}
